package main

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"log"
	"net/http"
	"time"
)

var (
	demoVecCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "AAAA",
		Subsystem: "BBBB",
		Name: "CCCC",
		Help: "DDDD",
	},
	[]string{"version"})
	metricsPath = "/metrics"
	listenAddr = "2345"
)
func main() {
	go func() {
		for  {
			demoVecCounter.With(prometheus.Labels{"version":"huwwei p50"}).Inc()
			time.Sleep(time.Second*10)
		}
	}()
	http.Handle("/metrics",promhttp.Handler())
	log.Printf("Starting Server at http://localhost:%s%s", listenAddr, metricsPath)
	log.Fatal(http.ListenAndServe(":"+listenAddr,nil))
}

// 注册指标
func init() {
	prometheus.MustRegister(demoVecCounter)
}
